package jp.android.ReversePlayer;

import java.io.File;

import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class Play extends Activity implements View.OnClickListener{
	
	private MediaPlayer player;
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
       setContentView(R.layout.play);
       
       // Toastのインスタンスを生成
       Toast toast = Toast.makeText(Play.this, "ファイル選択画面", Toast.LENGTH_LONG);
        // メッセージを表示
       toast.show();
       //変更後：アラート表示
       SelectFile();
       //初回再生
       //playSound();
	}
	
	public void playSound(){
        //再生
       try{
    	   stopSound();
    	   player = MediaPlayer.create(getApplicationContext(),R.raw.sample);
    	   player.seekTo(0);
    	   player.start();
    	   player.setOnCompletionListener((OnCompletionListener) this);
       }
       catch(Exception e){
       }
	}
	
	public void stopSound(){
		try{
			if(player==null){
				return;
			}
			player.stop();
			player.setOnCompletionListener(null);
			player.release();
			player=null;
		}
       catch(Exception e){
       }
	}
	public void onCompletion(MediaPlayer mediaPlayer){
		stopSound();
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}
    protected SelectFileDialog _dlgSelectFile;
    //
    private void SelectFile(){
    	//
		_dlgSelectFile = new SelectFileDialog(this);
		_dlgSelectFile.Show("/sdcard/");
	}
    public void onFileSelected_by_SelectFileDialog(File file){
		//SelectFileDialog
		if(file != null){
			Log.d("Test125","selected : " + file.getName());
		}
		else{
			Log.d("Test125","not selected");
		}
		_dlgSelectFile = null;
	}
	@Override
	public void onPause(){
		if(_dlgSelectFile != null){
			_dlgSelectFile.onPause();
		}
		super.onPause();
	}
}